package com.sunny.hp.common.servlet;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;


/**
 * ******************************************************************************
 * <PRE> * 프로그램 정보 *
 * 1. Project	: ncomz-erp
 * 2. Package	: com.ncomz.nzeip.common.servlet
 * 3. FileName	: ModelAndBEMSView.java
 * 4. 작성자		: P045701
 * 5. 작성일		: 2014. 6. 2. 오후 5:46:40
 * 6. 설명		:
 * </PRE>
 *******************************************************************************
 */
public class ModelAndNCOMZView extends ModelAndView {
	private static final String MOBILE_VIEWER_VIEW_NAME = "m/";
	
	private static HttpServletRequest request;
	private static HttpServletResponse response;
	private static HttpSession session;

	public ModelAndNCOMZView() {
		super();
	}

	public ModelAndNCOMZView(HttpServletRequest request) {		
		super();
		this.request = request;
	}
	
	public ModelAndNCOMZView(HttpServletRequest request, HttpServletResponse response) {		
		super();
		this.request = request;
		this.response = response;
	}

	public ModelAndNCOMZView(HttpServletRequest request,String viewName, Map<String, ?> model) {
		super(viewName, model);
		this.request = request;
	}



	public ModelAndNCOMZView(HttpServletRequest request,String viewName, String modelName, Object modelObject) {
		super(viewName, modelName, modelObject);
		this.request = request;
	}



	public ModelAndNCOMZView(HttpServletRequest request,String viewName) {
		super(viewName);
		this.request = request;
	}

	public ModelAndNCOMZView(HttpServletRequest request,View view, Map<String, ?> model) {
		super(view, model);
		this.request = request;
	}



	public ModelAndNCOMZView(HttpServletRequest request,View view, String modelName, Object modelObject) {
		super(view, modelName, modelObject);
		this.request = request;
	}



	public ModelAndNCOMZView(HttpServletRequest request,View view) {
		super(view);
		this.request = request;
	}
	
	public ModelAndNCOMZView(HttpServletRequest request,HttpSession session) {
		super();
		this.request = request;
		this.session = session;
	}


	/**
	 * <PRE>
	 * 1. MethodName	: setViewName
	 * 2. ClassName		: ModelAndNCOMZView
	 * 3. Commnet		: 
	 * 4. 작성자			: P044826
	 * 5. 작성일			: 2013. 12. 12. 오후 6:10:50
	 * </PRE>
	 * 		@param viewName
	 */
	@Override
	public void setViewName(String viewName) {
	      String agent = "iphone";
	      //System.out.println("================================= setViewName start ===============================");
		try {
			String hostName = request.getServerName();
			//System.out.println("================================= hostName ===============================> " + hostName);
				if(hostName.indexOf("m.skbems20.com") > -1){
					viewName = MOBILE_VIEWER_VIEW_NAME + viewName;
				}
				agent = request.getHeader("user-agent").toLowerCase();
				//System.out.println("================================= request.getHeader(\"user-agent\") ===============================> " + request.getHeader("user-agent"));
		} catch (Exception e) {
			agent = "";
			//System.out.println("================================= setViewName exception ===============================");
		}
		//System.out.println("================================= setViewName middle ===============================> " + agent);
			String [] mobileTarget = {"iphone", "ipod", "blackberry", "android", "windows ce", "lg", "mot", "samsung", "sonyericsson"};
			for(String target : mobileTarget){
				if(agent.indexOf(target) > -1){
					if(viewName.indexOf("m/") == 0){
						
					}else{
						//viewName = MOBILE_VIEWER_VIEW_NAME + viewName;
					
					}
					break;
				}
			}
			try {
				//System.out.println("================================= setViewName middle 1===============================");
				HttpSession session_ = request.getSession();
				//System.out.println("================================= setViewName middle 2===============================");
				session_.setAttribute("viewName", viewName);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				session.setAttribute("viewName", viewName);
			}

		super.setViewName(viewName);
	}



	/**
	 * <PRE>
	 * 1. MethodName	: getViewName
	 * 2. ClassName		: ModelAndBEMSView2
	 * 3. Commnet		: 
	 * 4. 작성자			: P044826
	 * 5. 작성일			: 2013. 12. 12. 오후 6:10:50
	 * </PRE>
	 * 		@return
	 */
	@Override
	public String getViewName() {
		// TODO Auto-generated method stub
		return super.getViewName();
	}



	/**
	 * <PRE>
	 * 1. MethodName	: setView
	 * 2. ClassName		: ModelAndBEMSView2
	 * 3. Commnet		: 
	 * 4. 작성자			: P044826
	 * 5. 작성일			: 2013. 12. 12. 오후 6:10:50
	 * </PRE>
	 * 		@param view
	 */
	@Override
	public void setView(View view) {
		// TODO Auto-generated method stub
		super.setView(view);
	}



	/**
	 * <PRE>
	 * 1. MethodName	: getView
	 * 2. ClassName		: ModelAndBEMSView2
	 * 3. Commnet		: 
	 * 4. 작성자			: P044826
	 * 5. 작성일			: 2013. 12. 12. 오후 6:10:50
	 * </PRE>
	 * 		@return
	 */
	@Override
	public View getView() {
		// TODO Auto-generated method stub
		return super.getView();
	}



	/**
	 * <PRE>
	 * 1. MethodName	: hasView
	 * 2. ClassName		: ModelAndBEMSView2
	 * 3. Commnet		: 
	 * 4. 작성자			: P044826
	 * 5. 작성일			: 2013. 12. 12. 오후 6:10:50
	 * </PRE>
	 * 		@return
	 */
	@Override
	public boolean hasView() {
		// TODO Auto-generated method stub
		return super.hasView();
	}



	/**
	 * <PRE>
	 * 1. MethodName	: isReference
	 * 2. ClassName		: ModelAndBEMSView2
	 * 3. Commnet		: 
	 * 4. 작성자			: P044826
	 * 5. 작성일			: 2013. 12. 12. 오후 6:10:50
	 * </PRE>
	 * 		@return
	 */
	@Override
	public boolean isReference() {
		// TODO Auto-generated method stub
		return super.isReference();
	}



	/**
	 * <PRE>
	 * 1. MethodName	: getModelInternal
	 * 2. ClassName		: ModelAndBEMSView2
	 * 3. Commnet		: 
	 * 4. 작성자			: P044826
	 * 5. 작성일			: 2013. 12. 12. 오후 6:10:50
	 * </PRE>
	 * 		@return
	 */
	@Override
	protected Map<String, Object> getModelInternal() {
		// TODO Auto-generated method stub
		return super.getModelInternal();
	}



	/**
	 * <PRE>
	 * 1. MethodName	: getModelMap
	 * 2. ClassName		: ModelAndBEMSView2
	 * 3. Commnet		: 
	 * 4. 작성자			: P044826
	 * 5. 작성일			: 2013. 12. 12. 오후 6:10:50
	 * </PRE>
	 * 		@return
	 */
	@Override
	public ModelMap getModelMap() {
		// TODO Auto-generated method stub
		return super.getModelMap();
	}



	/**
	 * <PRE>
	 * 1. MethodName	: getModel
	 * 2. ClassName		: ModelAndBEMSView2
	 * 3. Commnet		: 
	 * 4. 작성자			: P044826
	 * 5. 작성일			: 2013. 12. 12. 오후 6:10:50
	 * </PRE>
	 * 		@return
	 */
	@Override
	public Map<String, Object> getModel() {
		// TODO Auto-generated method stub
		return super.getModel();
	}



	/**
	 * <PRE>
	 * 1. MethodName	: addObject
	 * 2. ClassName		: ModelAndBEMSView2
	 * 3. Commnet		: 
	 * 4. 작성자			: P044826
	 * 5. 작성일			: 2013. 12. 12. 오후 6:10:50
	 * </PRE>
	 * 		@param attributeName
	 * 		@param attributeValue
	 * 		@return
	 */
	@Override
	public ModelAndView addObject(String attributeName, Object attributeValue) {
		// TODO Auto-generated method stub
		return super.addObject(attributeName, attributeValue);
	}



	/**
	 * <PRE>
	 * 1. MethodName	: addObject
	 * 2. ClassName		: ModelAndBEMSView2
	 * 3. Commnet		: 
	 * 4. 작성자			: P044826
	 * 5. 작성일			: 2013. 12. 12. 오후 6:10:50
	 * </PRE>
	 * 		@param attributeValue
	 * 		@return
	 */
	@Override
	public ModelAndView addObject(Object attributeValue) {
		// TODO Auto-generated method stub
		return super.addObject(attributeValue);
	}



	/**
	 * <PRE>
	 * 1. MethodName	: addAllObjects
	 * 2. ClassName		: ModelAndBEMSView2
	 * 3. Commnet		: 
	 * 4. 작성자			: P044826
	 * 5. 작성일			: 2013. 12. 12. 오후 6:10:50
	 * </PRE>
	 * 		@param modelMap
	 * 		@return
	 */
	@Override
	public ModelAndView addAllObjects(Map<String, ?> modelMap) {
		// TODO Auto-generated method stub
		return super.addAllObjects(modelMap);
	}



	/**
	 * <PRE>
	 * 1. MethodName	: clear
	 * 2. ClassName		: ModelAndBEMSView2
	 * 3. Commnet		: 
	 * 4. 작성자			: P044826
	 * 5. 작성일			: 2013. 12. 12. 오후 6:10:50
	 * </PRE>
	 */
	@Override
	public void clear() {
		// TODO Auto-generated method stub
		super.clear();
	}



	/**
	 * <PRE>
	 * 1. MethodName	: isEmpty
	 * 2. ClassName		: ModelAndBEMSView2
	 * 3. Commnet		: 
	 * 4. 작성자			: P044826
	 * 5. 작성일			: 2013. 12. 12. 오후 6:10:50
	 * </PRE>
	 * 		@return
	 */
	@Override
	public boolean isEmpty() {
		// TODO Auto-generated method stub
		return super.isEmpty();
	}



	/**
	 * <PRE>
	 * 1. MethodName	: wasCleared
	 * 2. ClassName		: ModelAndBEMSView2
	 * 3. Commnet		: 
	 * 4. 작성자			: P044826
	 * 5. 작성일			: 2013. 12. 12. 오후 6:10:50
	 * </PRE>
	 * 		@return
	 */
	@Override
	public boolean wasCleared() {
		// TODO Auto-generated method stub
		return super.wasCleared();
	}



	/**
	 * <PRE>
	 * 1. MethodName	: toString
	 * 2. ClassName		: ModelAndBEMSView2
	 * 3. Commnet		: 
	 * 4. 작성자			: P044826
	 * 5. 작성일			: 2013. 12. 12. 오후 6:10:50
	 * </PRE>
	 * 		@return
	 */
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return super.toString();
	}



	/**
	 * <PRE>
	 * 1. MethodName	: hashCode
	 * 2. ClassName		: ModelAndBEMSView2
	 * 3. Commnet		: 
	 * 4. 작성자			: P044826
	 * 5. 작성일			: 2013. 12. 12. 오후 6:10:50
	 * </PRE>
	 * 		@return
	 */
	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return super.hashCode();
	}



	/**
	 * <PRE>
	 * 1. MethodName	: equals
	 * 2. ClassName		: ModelAndBEMSView2
	 * 3. Commnet		: 
	 * 4. 작성자			: P044826
	 * 5. 작성일			: 2013. 12. 12. 오후 6:10:50
	 * </PRE>
	 * 		@param obj
	 * 		@return
	 */
	@Override
	public boolean equals(Object obj) {
		// TODO Auto-generated method stub
		return super.equals(obj);
	}



	/**
	 * <PRE>
	 * 1. MethodName	: clone
	 * 2. ClassName		: ModelAndBEMSView2
	 * 3. Commnet		: 
	 * 4. 작성자			: P044826
	 * 5. 작성일			: 2013. 12. 12. 오후 6:10:50
	 * </PRE>
	 * 		@return
	 * 		@throws CloneNotSupportedException
	 */
	@Override
	protected Object clone() throws CloneNotSupportedException {
		// TODO Auto-generated method stub
		return super.clone();
	}



	/**
	 * <PRE>
	 * 1. MethodName	: finalize
	 * 2. ClassName		: ModelAndBEMSView2
	 * 3. Commnet		: 
	 * 4. 작성자			: P044826
	 * 5. 작성일			: 2013. 12. 12. 오후 6:10:50
	 * </PRE>
	 * 		@throws Throwable
	 */
	@Override
	protected void finalize() throws Throwable {
		// TODO Auto-generated method stub
		super.finalize();
	}

	
}
